package middlewares

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

func InitMiddleware(c *gin.Context) {
	fmt.Println(time.Now())

	fmt.Println(c.Request.URL)

	//中间件与控制器之间共享数据
	c.Set("username", "张三")
	UserInfo := map[string]interface{}{
		"name": "张三",
		"age":  30,
	}

	c.Set("userInfo", UserInfo)

	// 定义一个goroutine统计日志
	cCp := c.Copy() //使用协程前必须要使用 c.Copy()
	go func() {
		time.Sleep(5 * time.Second)
		fmt.Println("Done!! in path " + cCp.Request.URL.Path)
	}()
}
